// 引入Sequelize模块
const Sequelize = require('sequelize');

// 引入数据库实例
const db = require('../db');

const contentImage = db.define("contentImage", {
    // 主键
    objectId: {
        type: Sequelize.STRING,
        allowNull: false,
        unique: true,
        primaryKey: true
    },

    images: {
        type: Sequelize.JSON,
        comment: "图片"
    },

    title: {
        type: Sequelize.STRING,
        comment: "标题"
    },

    desc: {
        type: Sequelize.TEXT,
        comment: "描述"
    },

    content: {
        type: Sequelize.TEXT,
        comment: "文案"
    },

    clickNum: {
        type: Sequelize.INTEGER,
        defaultValue: 0,
        comment: "点击次数"
    },

    classDesc: {
        type: Sequelize.TEXT,
        comment: "分类"
    },

    groupNum: {
        type: Sequelize.INTEGER,
        defaultValue: 0,
        comment: "排序"
    },

    tid: {
        type: Sequelize.STRING(20),
        comment: "模板Id"
    },

    type: {
        type: Sequelize.INTEGER,
        comment: "类型:0是文案，1是评语",
        defaultValue: 0,
    },

    createdAt: {
        type: Sequelize.DATE,
        get() {
            const rawValue = this.getDataValue('createdAt');
            return dateFormat(rawValue, 'yyyy-mm-dd HH:MM:ss');
        }
    },

    updatedAt: {
        type: Sequelize.DATE,
        get() {
            const rawValue = this.getDataValue('updatedAt');
            return dateFormat(rawValue, 'yyyy-mm-dd HH:MM:ss');
        }
    },
}, {
    underscored: false,
    tableName: "contentImage",
});

/*(async () => {
    contentImage.sync({
        alter: true
    });

    console.log("朋友圈文案同步成功")
})();*/

module.exports = contentImage;
